<?php
/**
 * Template Name: Careers
 **/ 
get_header(); 
if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="career-page">
    <?php
    $page_bg = get_field("background_image", get_the_ID());
    $bg_img = '';
    if(!empty($page_bg)) {
        $bg_img = 'style="background: url('.dynamic_url($page_bg['url']).') left center;background-size: 100% 100%; background-repeat: no-repeat;"';
    } 
    ?>
    <div class="container">
        <div class="content-inner" <?php echo $bg_img; ?>>
        
            <?php
            if(has_post_thumbnail(get_the_ID())) :
                $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full');?>
                <div class="head-thumb">     
                    <img src="<?php echo dynamic_url($thumb[0]); ?>" alt="<?php the_title();?>"/>
                </div>
            <?php endif; ?>
            
            <div class="head-content">
                <div class="left">
                    <?php
                    $head_left = get_field('header_left_content', get_the_ID());
                    _e($head_left); ?>
                </div>
                
                <?php //$head_color = get_field('header_background_color', get_the_ID()); ?>
                <div class="right">
                    <?php
                    //$head_right = get_field('header_right_content', get_the_ID());
                    //_e($head_right); ?>
                    <?php
                    $careers = new WP_Query(array(
                        'post_type' => 'careers',
                        'posts_per_page' => 4,
                        'order' => 'ASC',
                        'orderby' => 'menu_order'
                    ));
                    $main_career = "";
                    $count = 0;
                    if($careers->have_posts()) : ?>
                        <ul class="nav-tabs" role="tablist">
                            <?php
                            while($careers->have_posts()) :
                                $careers->the_post();
                                $sub_title = get_field("sub_title", get_the_ID());
                                $requirements = get_field("requirements", get_the_ID());
                                $requirements = apply_filters('the_content', $requirements);
                                 
                                if($careers->current_post == 0) :?>
                                
                                    <li class="active"><a href="#<?php echo sanitize_title(get_the_title());?>" role="tab" data-toggle="tab"><?php the_title(); ?></a></li>
                                <?php
                                    if(get_the_content() != "" || !empty($requirements)) : 
                                        $main_career .= '<div id="'.sanitize_title(get_the_title()).'" class="tab-pane fade in active">';
                                    endif;
                                    
                                else: ?>
                                
                                    <li><a href="#<?php echo sanitize_title(get_the_title());?>" role="tab" data-toggle="tab"><?php the_title(); ?></a></li>
                                <?php
                                    if(get_the_content() != "" || !empty($requirements)) :
                                        $main_career .= '<div id="'.sanitize_title(get_the_title()).'" class="tab-pane fade">';
                                    endif;
                                    
                                endif; ?>
                                
                                
                                <?php
                                //main careers content
                                if(empty($sub_title)) {
                                    $sub_title = get_the_title();
                                }
                                if(get_the_content() != "" || !empty($requirements)) {
                                    $main_career .= '
                                        <h1 id="aritist">'.get_the_title().'<span class="ab"> ('.$sub_title.')</span></h1>
                                            '.get_the_content().'
                                            <h1 class="kc-top">Requirements<span class="ab"> (Yêu cầu công việc)</span></h1>
                                            '.$requirements;
                                    $main_career .= "</div>";
                                }
                                ?>
                                
                            <?php endwhile; ?>
                        </ul>
                    <?php endif; 
                    wp_reset_postdata(); ?>
                </div>
            </div>
            
            <div class="middle-content">
                <div class="inner">
                    <div class="tab-content">
                        <?php _e($main_career);?>
                    </div>
                </div>
            </div>
            
            <?php 
            $bottom_image = get_field('bottom_background_image', get_the_ID());
            ?>
            <div class="bottom-content">
                <div class="inner" style="background: url('<?php echo dynamic_url($bottom_image['url']); ?>') no-repeat; -webkit-background-size: 100%; -moz-background-size: 100%; -o-background-size: 100%; background-size: 100%;">
                    <div class="hold-layer">
                        <?php 
                        //$bottom_content = get_field('bottom_content', get_the_ID());
                        //_e($bottom_content); ?>
                        <?php the_content(); ?>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>
<?php
endwhile; endif; 
get_footer(); ?>